package 作业;

public class 作业  {
    public static void main(String[] args) {
        Master master = new Master();
        master.feedDog("骨头");
        master.feedCat("鱼");
    }
}
class Master {
    private Pet mPet;
    private Food mFood;
    private Object name;

    public void feedCat(String food) {
        mPet = new Cat();
        Cat.name="小花";
        mFood = new Food(food);
        mPet.eat(mFood);
    }
    public void feedDog(String food) {
        mPet = new Dog();
        Dog.name ="旺财";
        mFood = new Food(food);
        mPet.eat(mFood);
    }
}
class Dog extends Pet{
    @Override
    public void eat(Food food) {
        System.out.println("正在喂小狗吃"+food.getFood());
        if (food.getFood().matches(Food.Bone)) {
            System.out.println("小狗正在吃"+food.getFood()+"！");
        }else {
            System.out.println("狗不吃"+food.getFood()+"!");
        }
    }
}
class Cat extends Pet{
    @Override
    public void eat(Food food) {
        System.out.println("正在喂小猫吃"+food.getFood());
        if (food.getFood().matches(Food.Fish)) {
            System.out.println("小猫正在吃"+food.getFood()+"！");
        }else {
            System.out.println("猫不吃"+food.getFood()+"!");
        }
    }
}
class Food {
    public final static String Bone = "骨头";
    public final static String Fish = "鱼";
    private String food;
    public String getFood() {
        return food;
    }
    public void setFood(String food) {
        this.food = food;
    }
    public Food(String food) {
        this.food = food;
    }
}
class Pet {
    public static String name;
    public void eat(Food food) {
    }

}
